package com.guonl.model;

import java.util.ArrayList;
import java.util.Arrays;

public class MyCountry {
    private Integer id;

    private String twoLetter;

    private String threeLetter;

    private Integer code;

    private String enName;

    private String chName;

    private String phonePre;

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getTwoLetter() {
        return twoLetter;
    }

    public void setTwoLetter(String twoLetter) {
        this.twoLetter = twoLetter == null ? null : twoLetter.trim();
    }

    public String getThreeLetter() {
        return threeLetter;
    }

    public void setThreeLetter(String threeLetter) {
        this.threeLetter = threeLetter == null ? null : threeLetter.trim();
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getEnName() {
        return enName;
    }

    public void setEnName(String enName) {
        this.enName = enName == null ? null : enName.trim();
    }

    public String getChName() {
        return chName;
    }

    public void setChName(String chName) {
        this.chName = chName == null ? null : chName.trim();
    }

    public String getPhonePre() {
        return phonePre;
    }

    public void setPhonePre(String phonePre) {
        this.phonePre = phonePre == null ? null : phonePre.trim();
    }

    public static MyCountry.Builder builder() {
        return new MyCountry.Builder();
    }

    public static class Builder {
        private MyCountry obj;

        public Builder() {
            this.obj = new MyCountry();
        }

        public Builder id(Integer id) {
            obj.setId(id);
            return this;
        }

        public Builder twoLetter(String twoLetter) {
            obj.setTwoLetter(twoLetter);
            return this;
        }

        public Builder threeLetter(String threeLetter) {
            obj.setThreeLetter(threeLetter);
            return this;
        }

        public Builder code(Integer code) {
            obj.setCode(code);
            return this;
        }

        public Builder enName(String enName) {
            obj.setEnName(enName);
            return this;
        }

        public Builder chName(String chName) {
            obj.setChName(chName);
            return this;
        }

        public Builder phonePre(String phonePre) {
            obj.setPhonePre(phonePre);
            return this;
        }

        public MyCountry build() {
            return this.obj;
        }
    }

    public enum Column {
        id("id", "id", "INTEGER", false),
        twoLetter("two_letter", "twoLetter", "VARCHAR", false),
        threeLetter("three_letter", "threeLetter", "VARCHAR", false),
        code("code", "code", "INTEGER", false),
        enName("en_name", "enName", "VARCHAR", false),
        chName("ch_name", "chName", "VARCHAR", false),
        phonePre("phone_pre", "phonePre", "VARCHAR", false);

        private static final String BEGINNING_DELIMITER = "\"";

        private static final String ENDING_DELIMITER = "\"";

        private final String column;

        private final boolean isColumnNameDelimited;

        private final String javaProperty;

        private final String jdbcType;

        public String value() {
            return this.column;
        }

        public String getValue() {
            return this.column;
        }

        public String getJavaProperty() {
            return this.javaProperty;
        }

        public String getJdbcType() {
            return this.jdbcType;
        }

        Column(String column, String javaProperty, String jdbcType, boolean isColumnNameDelimited) {
            this.column = column;
            this.javaProperty = javaProperty;
            this.jdbcType = jdbcType;
            this.isColumnNameDelimited = isColumnNameDelimited;
        }

        public String desc() {
            return this.getEscapedColumnName() + " DESC";
        }

        public String asc() {
            return this.getEscapedColumnName() + " ASC";
        }

        public static Column[] excludes(Column ... excludes) {
            ArrayList<Column> columns = new ArrayList<>(Arrays.asList(Column.values()));
            if (excludes != null && excludes.length > 0) {
                columns.removeAll(new ArrayList<>(Arrays.asList(excludes)));
            }
            return columns.toArray(new Column[]{});
        }

        public static Column[] all() {
            return Column.values();
        }

        public String getEscapedColumnName() {
            if (this.isColumnNameDelimited) {
                return new StringBuilder().append(BEGINNING_DELIMITER).append(this.column).append(ENDING_DELIMITER).toString();
            } else {
                return this.column;
            }
        }

        public String getAliasedEscapedColumnName() {
            return this.getEscapedColumnName();
        }
    }
}